<template>
  <div class="container">
    <div class="content_wraper" v-loading="showLoad">
      <div>
        <div class="left_cate">
          <p class="title">类别列表</p>
          <div class="left_con">
            <Tree
              ref="tree"
              :tree-data="treeData"
              @treeNodeClick="treeNodeClick"
            >
            </Tree>
          </div>
        </div>
        <div class="right_box">
          <div class="result_box">
            <el-table
              :data="lumionList"
              style="width: 100%; margin-bottom: 20px"
            >
              <el-table-column
                prop="name"
                label="名称"
                show-overflow-tooltip
                v-if="windowWidth > 900"
              >
              </el-table-column>
              <el-table-column
                prop="originalFileName"
                label="文件名称"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="fileSize"
                label="文件大小（kb）"
                show-overflow-tooltip
                v-if="windowWidth > 900"
              >
              </el-table-column>
              <el-table-column
                prop="plantScene"
                label="类别"
                show-overflow-tooltip
                v-if="windowWidth > 900"
              >
                <template slot-scope="scope">
                  <dict-tag
                    :options="dict.type.lumion_ins"
                    :value="scope.row.plantScene"
                  />
                </template>
              </el-table-column>
              <el-table-column label="操作" width="100">
                <template slot-scope="scope">
                  <i
                    class="iconfont icon-yunxiazai"
                    style="color: #1890ff; cursor: pointer"
                    @click="handleDownload(scope.row)"
                  ></i>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Tree from "@/components/Tree";
import { treeList } from '@/api/system/dict/data'
import { download } from '@/api/download.js'
import { getLumionList } from '@/api/lumion.js'

export default {
  name: "Lumion",
  components: {
    Tree
  },
  dicts: ['lumion_ins'],
  data() {
    return {
      showLoad: false,
      windowWidth: document.documentElement.clientWidth,
      insList: [],
      query: {
        current: 1,
        size: 100
      },
      lumionList: []
    };
  },
  computed: {
    imgUrl() {
      return process.env.VUE_APP_IP || ''
    },
    treeData() {
      return {
        showFile: true,
        isSearchShow: false,
        title: {
          isShow: false,
          setting: false,
          text: ""
        },
        defaultProps: {
          children: "children",
          label: "dictLabel"
        },
        data: this.insList
      };
    }
  },
  created() {
    this.getTreeselect('lumion_ins')
    this.getLumionList()
  },
  methods: {
    async getTreeselect(dictType) {
      const res = await treeList({ dictType })
      this.insList = res.data
    },
    async getLumionList() {
      const res = await getLumionList(this.query)
      const { data } = res
      this.lumionList = data.records
    },
    async treeNodeClick(obj, node) {
      // console.log(obj, node)
      const plantScene = obj.dictValue
      const params = Object.assign(this.query, { 'plantScene': plantScene })
      const res = await getLumionList(params)
      const { data } = res
      this.lumionList = data.records
    },
    handleDownload(row) {
      // console.log(row)
      this.showLoad = true
      this.$message.info("努力下载中，请稍后...")
      download(row.fileName)
      setTimeout(() => {
        this.showLoad = false
      }, 1500);
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-table::before {
  height: 0px;
}
::v-deep .el-table th.el-table__cell.is-leaf {
  border-bottom: 0px;
}
::v-deep .el-table td.el-table__cell {
  border-bottom: 0px;
}
::v-deep .el-table__fixed-right::before {
  height: 0px;
}
.result_item {
  padding: 5px;
  margin-bottom: 15px;
  height: 25vh;
  // border: 1px solid #ccc;
  cursor: pointer;
  &:hover {
    background: #fff;
    box-shadow: 0 2px 14px 0 rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    z-index: 1;
  }
}
@media screen and (max-width: 1130px) {
  .content_wraper .left_cate {
    margin-right: 24px;
  }
  .content_wraper .right_box {
    width: calc(100% - 256px);
  }
}
@media screen and (max-width: 909px) {
  .content_wraper .left_cate {
    // display: none;
    width: 90%;
    box-shadow: 0px 0px;
    min-height: 120px;
    overflow: auto;
    .title {
      display: none;
    }
  }
  .content_wraper .right_box {
    width: 100%;
  }
}

.container {
  height: 100vh;
  overflow: auto;
  background-color: #fff;
  background-image: url("../../assets/imgs/lumion_bg.png");
  background-size: 100% 100vh;
  // background-size: cover;
  background-repeat: no-repeat;
}
.content_wraper {
  height: 100%;
  max-width: 1130px;
  background: #fff;
  margin: auto;
  padding: 24px 0;
  // font-size: 0;
}
.left_cate {
  background: #fff;
  width: 235px;
  margin: 0 38px 0 0;
  display: inline-block;
  vertical-align: top;
  border-radius: 4px;
  // min-height: 80vh;
  padding: 0 5px;
  // box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.1);
  .title {
    display: flex;
    justify-content: center;
    margin: 16px auto 0px;
    font-size: 16px;
    color: #333;
    line-height: 22px;
    font-weight: 700;
  }
  .left_con {
    // min-height: 77vh;
    padding: 12px;
    border-radius: 5px;
    // box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.1);
    .type_item {
      font-size: 0;
      margin-bottom: 16px;
      overflow: hidden;
      position: relative;
      span {
        font-size: 14px;
        color: #999;
        margin: 5px 9px 0;
        line-height: 28px;
        display: inline-block;
        vertical-align: middle;
        cursor: pointer;
      }
    }
  }
}
.right_box {
  border-radius: 4px;
  display: inline-block;
  vertical-align: top;
  width: 852px;
  padding: 0 0 85px;
  background: #fff;

  // min-height: 654px;
  position: relative;
  padding-bottom: 85px;
}
.cate_box {
  padding: 20px 20px 8px;
  background: #fff;
  border-radius: 10px;
  .cate_item {
    display: flex;
    // align-items: center;
    margin: 16px 0;
  }
  .label {
    padding: 4px 0;
    margin: 10px 0;
    font-size: 16px;
    font-weight: 500;
    color: #000;
    line-height: 16px;
  }
  .tag_box {
    flex: 1;
    font-size: 14px;
    font-weight: 400;
    // color: #f1f2f3;
    ::v-deep .el-radio {
      font-size: 16px;
      color: #666;
    }
    ::v-deep .el-radio__input {
      display: none;
    }
    ::v-deep .el-radio__input.is-checked + .el-radio__label {
      color: #837eee;
      background: #eaf2fd;
      padding: 5px;
      border-radius: 6px;
    }
    ::v-deep .el-radio {
      margin: 10px 10px;
    }
  }
}
.result_box {
  padding-top: 16px;
  // height: 700px;
  // background-color: #f1f2f3;
}
</style>
